home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 019a / amac40.zip / RFR005.QM < prev    next >
Text File  |  1991-08-02  |  12KB  |  231 lines

  1. *                               RFR005.QM
  2. *                        Written By Tom Hogshead
  3. *                       [ See RFRMxx.QM For Use ]
  4. *                             August 2, 1991
  5. *  Key       Subfile                       Description
  6. * =====  ===============  ====================================================
  7. * @(0)                    Count Number Of Words In A Document,
  8. *                         Words Sep. By Space
  9. * @(9)                    Count Number Of Words In A Document,
  10. *                         Words=Letters/Num.
  11. * @(1)                    Count Number Of Characters In A Block
  12. * @(2)                    Count Number Of Characters In A Document
  13. *
  14. *          {e:\up\RFRM*}--Return To RFRMxx.QM
  15. *
  16. *-- eoi
  17.  
  18. * 
  19. * ┌─────────────────────────────────────────────────────────────┐
  20. * │@(0) Counts words in a document, words separated by spaces   │
  21. * └─────────────────────────────────────────────────────────────┘
  22. * @0 differs from @9 in that a "word" with @0 is considered any string
  23. * separated by at least one space.  @9 macro considers a "word" to be at
  24. * least one letter or number separated by a space or the following word
  25. * separators: !@#$%^&*'()+|-=\,./;'[]<>?:"{} ...  @9 counts words like
  26. * "can't" as two words; @0 counts them as one word.
  27. *
  28. * @0 is a little longer and slower than @9, but if it's important to
  29. * you that words be considered as "any string separated by at least
  30. * one space", this is the macro to use.
  31. * Test macro using the calibrated file WORD (46 words).
  32.  
  33. * -----------------------------------
  34. * @0 Macro To Count Words In Document
  35. * -----------------------------------
  36. *
  37. * [ Number of WORDS in document ] = [ Number of LINES in temp file ]
  38. *
  39. @0 Macrobegin
  40. *----Toggle Insert ON-------------------*
  41.         Insertline "A" Cursorleft "A"   * Insert test line
  42.         Endline Jtrue WASON:            * If not at endline-Insert is ON
  43.         Toggleinsert Jump WASOFF:       * Or Insert is off-toggle ON
  44.  WASON:  Cursorleft                     * Clean up cursor movement
  45.  WASOFF: Cursorleft Delline             * Clean up cursor movement
  46. *----Copy Document To Temp File---------*
  47.         BegFile Markblockbegin          * Mark document
  48.         EndFile Markblockend            *
  49.         Editfile "NUL" Return Quit      * Quit NUL of loaded
  50.         Editfile Return                 * Load NUL
  51.         Copyblock Unmarkblock           * Copy doc to temp file
  52.         Endfile Addline Begfile         * Add blank line at end
  53. *----Split Words One Word Per Line------*
  54.  COUNT1: Find " " Return  Return        * Find first space
  55.  COUNT2: Return                         * Put next word on next line
  56.  NOSPACE: CursorDown                    * Move down to next line
  57.         Jfalse DELBLANKLINES:           * If can't move down must be
  58.                                         * on last line, then begin to
  59.                                         * delete all blank lines
  60.         Cursorup                        * Move back up one line
  61.         Repeatfind                      * Find another space
  62.         JTrue COUNT2:                   * Put next word on next line
  63. *----Delete Blank Lines-----------------*
  64.  DELBLANKLINES: Begfile                 * Get to begin of file
  65.  CHK4BLANK: Endline Begline             * Check if line has text
  66.         Jtrue  NOTBLANK:                * If so, go to NOTBLANK
  67.         Delline                         * Or line is blank, delete it
  68.         Jtrue CHK4BLANK:                * Go check next line
  69.  NOTBLANK: Endpara                      *ELSE  Move to paragraph end
  70.         Cursordown                      * Move down to next line
  71.         Jtrue CHK4BLANK:                * If not eof, check again
  72. *----Get Word Count---------------------*
  73.  GETCOUNT:
  74.         Findreplace " " Return Delline  * Remove all extra spaces
  75.         Return "GN" Return              *
  76.         Makebotofscreen                 * WORD COUNT = # LINES
  77. *
  78. * 82 bytes Wed  02-20-1991  16:54:02
  79. * 83 bytes Mon  07-15-1991  11:06:17 (TH @0, changed ! to NUL)
  80.  
  81. * ┌────────────────────────────────────────────────────────────────────┐
  82. * │@(9) Macro To Count Words In Document, Words are letters and numbers│
  83. * └────────────────────────────────────────────────────────────────────┘
  84. * This macro counts the number of words in a document.  A "word" is at
  85. * least one letter or number separated by a space or the following word
  86. * separators:
  87. *                   !@#$%^&*'()+|-=\,./;'[]<>?:"{}
  88. * If it's important to you that words be considered as "any string
  89. * separated by at least one space", macro @0 below is the macro to
  90. * use.  The @9 macro counts words like "can't" as two words; @0 counts
  91. * them as one word.
  92. * Test macro using the calibrated file WORD (19 words).
  93.  
  94. * 
  95. * -----------------------------------
  96. * @9 Macro To Count Words In Document
  97. * -----------------------------------
  98. * [ Number of WORDS in document ] = [ Number of LINES in temp file ]
  99. *
  100. @9   Macrobegin                         *
  101. *----Be Sure Last Line Is Blank---------*
  102.      Endfile Begline                    * Check for blank line at end
  103.      Jfalse START: Addline              * If last line is NOT blank,
  104.                                         * test fails, then addline
  105. *----Copy Words To Scratch Buffer-------*
  106.  START: Begfile Insertline              * Insert blank line at top to
  107.                                         * be sure to find first word
  108.      Wordright Markword                 * Mark first word
  109.      Cursorup Delline                   * Delete blank line
  110.      Storescrbuff "1" Return            * Store word to scratch buffer
  111.  COUNT: Cursordown                      * Check if on last line
  112.      Jfalse GETCOUNT: Cursorup          * If can't cursor down, must
  113.                                         * be on last line, go to
  114.                                         * GETCOUNT, or cursorup
  115.                                         *ELSE
  116.      WordRight MarkWord                 * Move to next word and mark it
  117.      Jfalse COUNT:                      * If at endline, no word exists
  118.                                         * so COUNT again
  119.                                         *ELSE
  120.      Appendscrbuff "1" Return           * Append word to scratch
  121.      Jump COUNT:                        * and go-to COUNT again
  122. *----Get Word Count---------------------*
  123.  GETCOUNT: Editfile "NUL" Return Quit   * Quit NUL if loaded
  124.      Editfile Return                    * Load temp file to count words
  125.      Getscrbuff "1" Return              * Make list of words
  126.      Unmarkblock Endfile                * WORD COUNT = # LINES
  127. *
  128. * 50 bytes Sat  10-13-1990  03:18:33
  129. * 54 bytes Mon  07-15-1991  11:09:03 (TH @9, changed ! to NUL)
  130.  
  131. * 
  132. * ----------------------------------------------------------------------
  133. * @(1) Count Number Of Characters In A Block
  134. * ----------------------------------------------------------------------
  135. * To: Mike Butler, RelayNet, May 4, 1991  15:16:09
  136. * MB> Is there any way to create a macro to count the number of
  137. * MB> characters in a block?
  138.  
  139. * This QEdit macro determines a block's byte size and provides a means
  140. * to calculate the Number of Characters in a block.  Block Byte Size can
  141. * be useful for uploading CompuServe files where upload file descriptions
  142. * are limited to 465 bytes:
  143. *     Block Byte Size = Size of block if it were a file
  144. *     Character Count = (Block Byte Size) minus 2 x (Number of Lines)
  145. * Mark a block.  Block need not be closed.  Block byte size will be shown in
  146. * a window and in front of the last line of a copy of the block.  Press
  147. * <enter> to remove the window from the screen and return to the our
  148. * starting point.  To determine the number of actual characters in a block,
  149. * including spaces between text, subtract 2 x (number of lines in window)
  150. * from (byte size).  The paragraph below with asterisks is 274 bytes, and
  151. * has 274 - 4 x 2 = 266 characters including spaces.
  152.  
  153. * NOTE: c:temp and c:dir are temporary files created and deleted from the
  154. * disk.  Rename files and run QMAC if this causes problems.  This macro has
  155. * only been tested with DOS 3.3.  SaveFile is used rather than WriteBlock
  156. * in case c:temp and c:dir exist before running.
  157.  
  158. @1 Macrobegin
  159.         Editfile "c:temp" Return        * Load temp file
  160.         killfile Quit                   * Kill/quit c:temp
  161.         EditFile Return                 * Load empty c:temp
  162.         Copyblock                       * Copy block to temp file
  163.         EndFile DelLine                 * Delete extra blank line
  164.         Savefile                        * Save temp file to get size
  165.         DOS "Dir " Currentfilename      * Get  DIR list of c:temp
  166.         ">C:dir" Return Return          * Save DIR list of c:temp
  167.         Editfile "C:dir" Return         * Load DIR list
  168.         Gotoline "5" Return             * CursorDown to c:temp line
  169.         Wordright Markword Copy         * Copy size to scrap
  170.         Killfile Quit                   * Kill/quit c:dir
  171.         Editfile "c:temp" Return        * Load c:temp
  172.         Killfile                        * Kill it
  173.         Endfile Begline                 *
  174.         "Block size=" Paste             * Paste block size at bottom
  175.         Makebotofscreen                 * Re-position
  176.         Pause                           * Press <enter> to remove block size
  177.         Quit                            * Character Count = Block Size
  178.                                         *     minus 2 x Number of Lines
  179. * 114 bytes Sat  05-04-1991  15:15:25
  180.  
  181. * The following macro counts the number of characters in a document.  After
  182. * running, the byte size of the document *without* spaces is shown in
  183. * column 1 on the last line.  Subtract 2 x number of lines from the byte
  184. * size to get the number of actual characters in the document.
  185.  
  186. * 
  187. * ----------------------------------------------------------------------
  188. * @(2) Count Number Of Characters In A Document
  189. * ----------------------------------------------------------------------
  190.  
  191. @2 Macrobegin
  192.         UnMarkBlock                     * Un-mark all blocks
  193.         BegFile Markblockbegin          * Mark document
  194.         EndFile Markblockend            *
  195.         Editfile "c:temp" Return        * Load empty c:temp
  196.         Killfile Quit                   * Kill/quit c:temp
  197.         Editfile Return                 * Load empty temp file
  198.         Copyblock Unmarkblock           * Copy document to temp file
  199.         Findreplace " " Return          * Replace all single spaces
  200.         DelLine Return "GN" Return      * With Blanks, globally
  201.  DELBLANKLINES:                         *
  202.         Begfile                         * Get to begin of file
  203.  CHK4BLANK:                             *
  204.         Endline Begline                 * Check if line has text
  205.         Jtrue  NOTBLANK:                * If so, go to NOTBLANK
  206.         Delline                         * Or line is blank, delete it
  207.         Jtrue CHK4BLANK:                * Go check next line
  208.  NOTBLANK:                              *
  209.         Endpara                         *ELSE  Move to paragraph end
  210.         Cursordown                      * Move down to next line
  211.         Jtrue CHK4BLANK:                * If not eof, check again
  212.  GETCOUNT:                              *
  213.         Savefile                        * Save temp file to get size
  214.         DOS "DIR " Currentfilename      * Get  DIR list of c:temp
  215.         ">C:dir" Return Return          * Save DIR list of c:dir
  216.         Editfile "C:dir" Return         * Load DIR list
  217.         Gotoline "5" Return             * Cursordown to c:temp line
  218.         Wordright Markword Copy         * Copy size to scrap
  219.         Killfile Quit                   * Kill/quit c:dir
  220.         Editfile  "c:temp" Return       * Load compressed c:temp
  221.         Killfile                        * Kill c:temp disk copy
  222.         Begline "Byte size=" Paste      * Paste byte size at bottom
  223.         Makebotofscreen                 * Re-position
  224.         Pause                           * Press <enter> to remove window
  225.         Quit                            * Character Count = Byte Size
  226.                                         *     minus 2 x Number of Lines
  227. * 92 bytes Wed  02-20-1991  17:02:29
  228. * 141 bytes Sat  05-04-1991  15:38:07 changed temp file names, added pause
  229. *                                     corrected gotoline "5"
  230.  
  231.